﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MotionCS.Controller;

namespace MotionCS.Module
{
    public interface ICylinder
    {
        /// <summary>
        /// 标志符
        /// </summary>
        //DoE Identifier { get; }

        /// <summary>
        /// 运动到工作位
        /// </summary>
        /// <returns></returns>
        int MoveToWork();
        /// <summary>
        /// 运动到初始位
        /// </summary>
        /// <returns></returns>
        int MoveToBase();

        bool IsOn();
    }

    public class CylinderConfig
    {
        /// <summary>
        /// 气缸名称
        /// </summary>
        public string Name { get; set; }
        /// <summary>
        /// 气缸输出
        /// </summary>
        public IDoBit Dout { get; set; }
    }

    public class AirCylinder : ICylinder
    {
        /// <summary>
        /// 气缸配置
        /// </summary>
        private CylinderConfig config = new CylinderConfig();
        public CylinderConfig Config { get => config; set => config = value; }
        /// <summary>
        /// 控制IO
        /// </summary>
        private IDoBit DoBit { get; set; } 
        /// <summary>
        /// 默认构造函数
        /// </summary>
        public AirCylinder(CylinderConfig cylinderConfig)
        {
            config = cylinderConfig;
            DoBit = config.Dout;
        }
        /// <summary>
        /// 运动到工作位
        /// </summary>
        public int MoveToWork()
        {
            DoBit.TurnOn();
            return 0;
        }
        /// <summary>
        /// 运动到初始位
        /// </summary>
        public int MoveToBase()
        {
            DoBit.TurnOff();
            return 0;
        }

        public bool IsOn()
        {
            return DoBit.IsTurnOn();
        }
    }
}
